<?php

declare(strict_types=1);

namespace App\Payment\Model;

use Hyperf\Database\Model\Events\Created;
use Hyperf\Database\Model\Events\Updated;
use Mine\MineModel;

/**
 * @property int $id
 * @property string $title 支付名称
 * @property string $icon 支付图标
 * @property int $device 设备 1web 2android 3ios,4.h5
 * @property int $method 支付方式 80001支付宝 80002微信 80003云闪付 80004银行卡80005 ios
 * @property string $channel_name 渠道名称
 * @property string $channel_type 渠道类型
 * @property float $sort 排序
 * @property int $status 状态 1可用0不可用
 * @property string $setting 渠道配置
 * @property int $is_default 是否默认1是0否
 * @property int $timeout 支付超时时间
 * @property int $create_time 创建时间
 * @property int $update_time 更新时间
 * @property int $delete_time 删除时间
 * @property int $created_by 创建人
 */
class PaymentMethod extends MineModel
{
    protected ?string $dateFormat = 'U';
    const CREATED_AT = 'create_time';
    const UPDATED_AT = 'update_time';
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'payment_method';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'title', 'icon', 'device', 'method', 'channel_name', 'channel_type', 'sort', 'status', 'setting', 'is_default', 'timeout', 'create_time', 'update_time', 'delete_time', 'created_by'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'device' => 'integer', 'method' => 'integer', 'sort' => 'float', 'status' => 'integer', 'is_default' => 'integer', 'timeout' => 'integer', 'create_time' => 'integer', 'update_time' => 'integer', 'delete_time' => 'integer', 'created_by' => 'integer'];

    public function getSettingAttribute($value)
    {
        return !empty($value) ? json_decode($value, true) : [];
    }

    public function setSettingAttribute($value)
    {
        $this->attributes['setting'] = !empty($value) ? json_encode($value) : '';
    }

    public function created(Created $event)
    {
        echo '-----用户新增后---->>' . PHP_EOL;
    }

    public function updated(Updated $event)
    {
        echo '-----member更新---->>' . PHP_EOL;
    }
}
